#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

enum class Token {
    ERROR = -2,
    END = -1,
    NUMBER = 0,
    ADD,
    SUB,
    MUL,
    DIV,
    ADD_ARR,
    SUB_ARR,
    POWER,
    LP,
    RP
};
struct TokenInfo {
    Token type;
    double num;
};
class TokenStream {
private:
    string strIn;
    int pos;

public:
    TokenStream() = delete;
    TokenStream(string &str) : strIn(str), pos(0) {}
    TokenStream(string &&str) : strIn(str), pos(0) {}
    int getPos() { return pos; }
    string &getSin() { return strIn; }
    TokenInfo nextToken() {
        TokenInfo ti{Token::END};
        while (true) {
            if (pos >= strIn.length()) {
                ti.type = Token::END;
                break;
            }
            if (strIn[pos] == ' ' || strIn[pos] == '\t') {
                pos++;
                continue;
            } else if (isdigit(strIn[pos])) {
                double num = 0.0;
                double base = 10.0;
                double decimal = 0.0;
                double exp = 1.0;
                while (pos < strIn.length() && isdigit(strIn[pos])) {
                    num = num * base + int(strIn[pos] - '0');
                    pos++;
                }
                if (pos < strIn.length() && strIn[pos] == '.') {
                    base = 0.1;
                    pos++;
                    while (pos < strIn.length() && isdigit(strIn[pos])) {
                        decimal += (strIn[pos] - '0') * base;
                        base *= 0.1;
                        pos++;
                    }
                }
                if (pos < strIn.length() && toupper(strIn[pos]) == 'E') {
                    bool neg = false;
                    if (strIn[pos] == '-') {
                        neg = true;
                    } else if (strIn[pos] == '+') {
                        neg = false;
                    }
                    base = 10.0;
                    exp = 0.0;
                    while (pos < strIn.length() && isdigit(strIn[pos])) {
                        exp = exp * base + strIn[pos] - '0';
                        pos++;
                    }
                    exp = neg ? -exp : exp;
                }
                ti.type = Token::NUMBER;
                ti.num = pow(num + decimal, exp);
                pos--;
            } else if (strIn[pos] == '+') {
                ti.type = Token::ADD;
            } else if (strIn[pos] == '-') {
                ti.type = Token::SUB;
            } else if (strIn[pos] == '*') {
                ti.type = Token::MUL;
            } else if (strIn[pos] == '/') {
                ti.type = Token::DIV;
            } else if (strIn[pos] == '^') {
                ti.type = Token::POWER;
            } else if (strIn[pos] == '.') {
                double base = 10.0;
                double decimal = 0.0;
                double exp = 0.0;
                base = 0.1;
                pos++;
                while (isdigit(strIn[pos])) {
                    decimal += (strIn[pos - '0']) * base;
                    base *= 0.1;
                }
                if (toupper(strIn[pos]) == 'E') {
                    bool neg = false;
                    if (strIn[pos] == '-') {
                        neg = true;
                    } else if (strIn[pos] == '+') {
                        neg = false;
                    }
                    base = 10.0;
                    while (isdigit(strIn[pos])) {
                        exp = exp * base + strIn[pos] - '0';
                    }
                    exp = neg ? -exp : exp;
                }
                ti.type = Token::NUMBER;
                ti.num = pow(decimal, exp);
                pos--;
            } else if (strIn[pos] == '(') {
                ti.type = Token::LP;
            } else if (strIn[pos] == ')') {
                ti.type = Token::RP;
            } else {
                ti.type = Token::ERROR;
                pos--;
            }
            pos++;
            break;
        }
        return ti;
    }
};

class Cal {
private:
    TokenStream ts;
    int error;

public:
    Cal() = delete;
    Cal(string &str) : ts(str), error(0) {}
    bool getError() { return error; }

    void inOrderToSuffix(vector<TokenInfo> &suffix) {
        TokenInfo curTi{Token::END}, lastTi;
        vector<double> operand;
        vector<Token> operat;
        unordered_map<Token, int> precHash = {
            {Token::ADD, 0},     {Token::SUB, 0},   {Token::MUL, 1},
            {Token::DIV, 1},     {Token::POWER, 2}, {Token::ADD_ARR, 3},
            {Token::SUB_ARR, 3}, {Token::LP, 4}};
        while (true) {
            lastTi = curTi;
            curTi = ts.nextToken();
            if (curTi.type == Token::ERROR) {
                error = 1;
                break;
            } else if (curTi.type == Token::END) {
                break;
            } else if (curTi.type == Token::NUMBER) {
                suffix.emplace_back(curTi);
            } else if (curTi.type == Token::ADD || curTi.type == Token::SUB ||
                       curTi.type == Token::MUL || curTi.type == Token::DIV ||
                       curTi.type == Token::POWER) {
                if (curTi.type == Token::ADD && lastTi.type != Token::NUMBER &&
                    lastTi.type != Token::RP) {
                    operat.emplace_back(Token{Token::ADD_ARR});
                    continue;
                }
                if (curTi.type == Token::SUB && lastTi.type != Token::NUMBER &&
                    lastTi.type != Token::RP) {
                    operat.emplace_back(Token{Token::SUB_ARR});
                    continue;
                }
                while (!operat.empty() && operat.back() != Token::LP &&
                       precHash[curTi.type] <= precHash[operat.back()]) {
                    suffix.emplace_back(TokenInfo{operat.back()});
                    operat.pop_back();
                }
                operat.emplace_back(curTi.type);
            } else if (curTi.type == Token::LP) {
                operat.emplace_back(curTi.type);
            } else if (curTi.type == Token::RP) {
                while (!operat.empty() && operat.back() != Token::LP) {
                    suffix.emplace_back(TokenInfo{operat.back()});
                    operat.pop_back();
                }
                if (operat.empty()) {
                    error = 2;
                    break;
                }
                operat.pop_back();
            } else {
                break;
            }
        }
        if (error == 0) {
            while (!operat.empty()) {
                suffix.emplace_back(TokenInfo{operat.back()});
                operat.pop_back();
            }
        }
    }
    double getResult() {
        double res = 0.0;
        vector<double> resStack;
        vector<TokenInfo> suffix;
        unordered_map<Token, string> token2Str = {
            {Token::ADD, "+"},      {Token::SUB, "-"},
            {Token::MUL, "*"},      {Token::DIV, "/"},
            {Token::POWER, "^"},    {Token::ADD_ARR, "#+#"},
            {Token::SUB_ARR, "#-#"}};
        inOrderToSuffix(suffix);
        if (getError() != 0) {
            return res;
        }
        auto doOperator = [](double left, double right, Token type) -> double {
            double res = 0.0;
            if (type == Token::ADD) {
                res = left + right;
            } else if (type == Token::SUB) {
                res = left - right;
            } else if (type == Token::MUL) {
                res = left * right;
            } else if (type == Token::DIV) {
                res = left / right;
            } else if (type == Token::POWER) {
                res = pow(left, right);
            } else if (type == Token::SUB_ARR) {
                res = -right;
            } else if (type == Token::ADD_ARR) {
                res = right;
            }
            return res;
        };
        for (int i = 0; i < suffix.size(); i++) {
            TokenInfo curTi = suffix[i];
            string echo = curTi.type == Token::NUMBER ? to_string(curTi.num)
                                                      : token2Str[curTi.type];
            echo += ' ';
            cout << echo;
            if (curTi.type == Token::NUMBER) {
                resStack.emplace_back(suffix[i].num);
            } else if (curTi.type == Token::ADD || curTi.type == Token::SUB ||
                       curTi.type == Token::MUL || curTi.type == Token::DIV ||
                       curTi.type == Token::POWER ||
                       curTi.type == Token::ADD_ARR ||
                       curTi.type == Token::SUB_ARR) {
                double left = 0.0, right = 0.0;
                if (resStack.empty()) {
                    error = 3;
                }
                right = resStack.back();
                resStack.pop_back();
                if (curTi.type != Token::ADD_ARR &&
                    curTi.type != Token::SUB_ARR) {
                    if (resStack.empty()) {
                        error = 4;
                        break;
                    }
                    left = resStack.back();
                    resStack.pop_back();
                }
                resStack.emplace_back(doOperator(left, right, curTi.type));
            } else {
                error = 5;
                break;
            }
        }
        if (!resStack.empty()) {
            res = resStack.back();
        }
        cout << endl;
        return res;
    }
    void formatError() {
        string errMsg = ts.getSin() + "\n";
        int len = ts.getPos();
        for (int i = 0; i < len; i++) {
            errMsg += ' ';
        }
        errMsg += "^\n" + to_string(error);
        cout << errMsg << endl;
    }
};

int main() {
    string line;
    cout << "> ";
    while (getline(cin, line)) {
        if (line.length() == 0) {

        } else {
            Cal cal(line);
            double res = 0.0;
            res = cal.getResult();
            if (cal.getError() != 0) {
                cal.formatError();
            } else {
                cout << " = " << res << endl;
            }
        }
        cout << "> ";
    }
    return 0;
}